package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;
import java.util.List;

/**
 * @Description NursingProjectController
 * @Author Wen Jie
 * @Date 2024-09-05
 */
@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理")
public class NursingProjectController extends BaseController{

    @Autowired
    private NursingProjectService nursingProjectService;

    @GetMapping
    @ApiOperation("分页查询护理项目列表")
    public ResponseResult<PageResponse<NursingProjectVo>> getByPage(
            @ApiParam(value = "护理项目名称")
            @RequestParam(value = "name", required = false) String name,
            @ApiParam(value = "状态：0-禁用，1-启用")
            @RequestParam(value = "status", required = false) Integer status,
            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量")
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        PageResponse<NursingProjectVo> nursingProjectPageInfo = nursingProjectService.getByPage(name, status, pageNum, pageSize);
        return ResponseResult.success(nursingProjectPageInfo);
    }
    @PostMapping
    @ApiOperation("新增护理项目")
    public ResponseResult addNursingProject(
            @ApiParam(value = "护理项目信息")
            @RequestBody NursingProjectVo nursingProjectVo
    ){
        nursingProjectService.addNursingProject(nursingProjectVo);
        return success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理项目")
    public ResponseResult<NursingProjectVo> getById(@ApiParam(value = "护理项目id",required = true) @PathVariable("id") Long id){
        NursingProjectVo nursingProjectVo = nursingProjectService.getById(id);
        return success(nursingProjectVo);
    }

    @PutMapping
    @ApiOperation("修改护理项目")
    public ResponseResult updateNursingProject(@ApiParam("护理项目信息") @RequestBody NursingProjectVo nursingProjectVo){
        nursingProjectService.updateNursingProject(nursingProjectVo);
        return success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除项目")
    public ResponseResult deleteById(@ApiParam("项目id") @PathVariable("id") Long id){
        nursingProjectService.deleteById(id);
        return success();
    }

    @GetMapping("/all")
    @ApiOperation("查询所有项目")
    public ResponseResult<List<NursingProjectVo>> getAll(){
        List<NursingProjectVo> nursingProjectVos = nursingProjectService.getAll();
        return success(nursingProjectVos);
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("修改项目状态")
    public ResponseResult updateStatusById(
            @ApiParam("项目id") @PathVariable(value = "id",required = true) Long id,
            @ApiParam("项目状态") @PathVariable(value = "status",required = true) Integer status
    ){
        nursingProjectService.updateStatusById(id,status);
        return success();
    }

}
